module MC.View {
	export class FacShow {
		public constructor(type: any) {
			this.type = type;
			this.init();
		}
		private type: any;
		private init() {
			MC.apiD('/api/home/customer/detail', {
				uid: MC.get('uid'),
				type: this.type
			}, (data: any) => {
				console.log(data);
				this.showBase(data.base);
				if (data.kz) {
					$('[data-id=5],[data-id=6],[data-id=7],[data-id=8],[data-id=9]').show();
					this.showKz(data.kz);
				}

				if (data.huodan) {
					this.showHuodan(data.huodan);
				}

                if (data.gangwei) {
                    this.showGangwei(data.gangwei);
                }




			});

			$(".facHomeMenu").on("click", function () {
				var id = this.getAttribute('data-id');
				$('.facHomeMenu').removeClass('facHomeMenuActive');
				$(this).addClass('facHomeMenuActive');
				$('.facHomeList').hide();
				$('.facHomeList' + id).show();
			});



		}


		private showBase(data: any) {
			//	console.log(data);
			data.age_range = MC.API.tihuan(data.age_range, ',', '-');
			$('#age_range').text(data.age_range);
			$('#com_address').text(data.com_address);
			$('#com_city').text(data.com_city);
			$('#com_fax').text(data.com_fax);

			$('#com_name').text(data.com_name);
			$('#com_tel').text(data.com_tel);
			$('#detail').text(data.detail);
			$('#facType').text(data.facType);

			$('#legal_mobile').text(data.legal_mobile);
			$('#legal_name').text(data.legal_name);
			$('#legal_sex').text(data.legal_sex);
			$('#quality').text(data.quality+'%');
			if (data.param) {
				$('#back').text(data.param.back);
				$('#bale').text(data.param.bale);
				$('#cut').text(data.param.cut);

				$('#output').text(data.param.output);
				$('#piece').text(data.param.piece);
				$('#single').text(data.param.single);

				$('#total').text(data.param.total);
				$('#truck').text(data.param.truck);

			}
			if (data.out_type && data.out_type.length > 0) {
				for (let i = 0; i < data.out_type.length; i++) {
					let li = data.out_type[i];
					let str = `<li class="tabli">` + li + `</li>`;
					$('#out_type').append(str);
				}
			} else {
				$('#out_type,.Titleout_type').hide();
			}
		}

		private showKz(data: any) {
			console.log(data);
			let com_licences = data.com_licences;

			if (com_licences && com_licences != '无权限') {
				$('#honor').attr('src', com_licences.honor);
				$('#house').attr('src', com_licences.house);
				$('#licence').attr('src', com_licences.licence);
				$('#rent').attr('src', com_licences.rent);

				$('#swdj').attr('src', com_licences.swdj);
				$('#yyzz').attr('src', com_licences.yyzz);
				$('#zzjgdm').attr('src', com_licences.zzjgdm);
			} else {
				$('.com_licences .wuquanxian').show();
				$('.com_licences .imgul').hide();
				if (com_licences != '无权限') {
					$('.com_licences .wuquanxian').text('该公司没有填写');
				}
			}
			if (data.equips) {
				this.showshebei(data.equips, data.equips_name);
			}
			if (data.yields) {
				this.showyields(data.yields);
			}
			if (data.envs) {
				this.showenvs(data.envs);
			}
			/*if (data.costlist) {
				this.costlist(data.costlist);
			}*/
			//console.log("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaff");
		}

		private getName(names: any, id: any) {
			for (let i = 0; i < names.length; i++) {
				if (names[i].id == id) {
					return names[i].name;
				}
			}
			return '未知';
		}
		private showshebei(data: any, names: any) {
			for (let i = 0; i < data.length; i++) {
				let one = data[i];
				let name = this.getName(names, one[0]);
				//console.log(one,name);
				if (one[4] && one[4] == '1') {
					let pinpai = one[1] || '无';
					let nianxian = one[2] || '无';
					let shuliang = one[3] || '无';
					let li = `<li class="li">
                    <span class="name">`+ name + `</span>
					<span class="pinpai">`+ pinpai + `</span>
                    <span class="nianxian">`+ nianxian + `</span>
                    <span class="shuliang">`+ shuliang + `</span>
              		  </li>`;
					$('.shebeiul').append(li);
				}
			}
		}

		private showyields(data: any) {
			//console.log(data);
			for (let i = 0; i < data.departs.length; i++) {
				let one = data.departs[i];
				let li = ` <li class="li">
                    <span class="title">`+ one.key + `</span>
                    <span class="value">`+ one.num + `</span>
                </li>`;
				$('.departs').append(li);
			}
			for (let i = 0; i < data.requirePros.length; i++) {
				let one = data.requirePros[i];
				if (one.val == '1') {
					one.val = '一道';
				} else if (one.val == '2') {
					one.val = '二道';
				} else if (one.val == '3') {
					one.val = '三道';
				} else {
					one.val = '';
				}

				let li = ` <li class="li">
                    <span class="title">`+ one.key + `</span>
                    <span class="value">`+ one.val + `</span>
                </li>`;
				$('.requirePros').append(li);
			}
			for (let i = 0; i < data.requireDeparts.length; i++) {
				let one = data.requireDeparts[i];
				let li = ` <li class="li">
                    <span class="title">`+ one.key + `</span>
                    <span class="value">`+ one.num + `</span>
                </li>`;
				$('.requireDeparts').append(li);
			}

			for (let i = 0; i < data.standards.length; i++) {
				let one = data.standards[i];
				if (one == '1') {
					$('.standards [showid=' + i + ']').show();
				} else {
					$('.standards [showid=' + i + ']').hide();
				}
			}

			if (data.dayOutPuts && data.dayOutPuts.length > 1) {
				$('.dayOutPuts').text(data.dayOutPuts[0] + '-' + data.dayOutPuts[1]);
			}

		}

		private showenvs(data: any) {
			$('#backShow').attr('src', data.backShow);
			$('#caijian').attr('src', data.caijian);
			$('#facManagerShow').attr('src', data.facManagerShow);

			$('#financeShow').attr('src', data.financeShow);
			$('#guardShow').attr('src', data.guardShow);
			$('#managerShow').attr('src', data.managerShow);

			$('#rawShow').attr('src', data.rawShow);
			$('#techShow').attr('src', data.techShow);
			$('#waixingtu').attr('src', data.waixingtu);

			$('#workShow').attr('src', data.workShow);
			$('#yangyi').attr('src', data.yangyi);
		}

		private costlist(costlist: any) {
			var Table = new MC.Order.Table($('#costlist'));
			Table.hangText = false;
			Table.lieText = '自定义成本标题';
			Table.readOnly = true;
			Table.init();
			if (costlist && costlist !== '') {
				Table.setData(costlist);
			} else {
				Table.sethang('数值');
				Table.setlie('房租,水电,税收,生活费,裁剪,缝制,校验,打眼钉扣,整烫,包装,货运,设备折旧,耗材损耗');
			}
			Table.create();
		}


		/*** 显示货单 */
		private showHuodan(data: any) {
			if (data.length == 0) {
				$('.huodanUl').append(`<p class="nullHuodan">该公司没有添加货单,或者货单到期</p>`);
				return;
			}

			for (let i = 0; i < data.length; i++) {
				let one = data[i];
				let qiangdan = '';
				if (one.is_rob == MC.DEL.OrderBaleModel.is_rob_qiangdan) {
					qiangdan = 'qiangdan';
				}
				let html = `<li class="li">
                    <a class="order" href="/h5/order/orderShow.html?id=`+ one.id + `">
                        <div class="goodsdiv">
                            <i class="tagico `+ qiangdan + `"></i>
                            <img class="img" src="`+ one.img + `">
                        </div>
                        <span class="p">`+ one.name + `</span>
                        <span class="date">`+ one.periodStr + `</span>
                    </a>
                </li>`;
				$('.huodanUl').append(html);
			}
		}


		private showGangwei(ul:any){
            MC.View.jobs_ul('.facHomeList .jobs_ul',ul);
		}


	}
}